package main

import (
	"context"
	"fmt"
	"github.com/go-test/k8s-client-go/common"
	apps_v1 "k8s.io/api/apps/v1"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
)

func main() {
	var (
		clientset *kubernetes.Clientset
		err       error
		dp        *apps_v1.Deployment
	)

	// 初始化k8s客户端
	if clientset, err = common.InitClient(); err != nil {
		goto FAIL
	}
	// 获取default命名空间下指定的deployment
	if dp, err = clientset.AppsV1().Deployments("default").Get(context.TODO(), "busybox", meta_v1.GetOptions{}); err != nil {
		goto FAIL
	} else {
		var num int32
		num = 2
		dp.Spec.Replicas = &num
		_, err = clientset.AppsV1().Deployments("default").Update(context.TODO(), dp, meta_v1.UpdateOptions{})
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println("更新成功")

	}

	return

FAIL:
	fmt.Println(err)
	return
}
